<template>
	<view class="model" v-show="modelShow">
		<image src="../../static/logo (2).png" mode=""></image>
		<view class="title">
			{{title}}
		</view>
		<view class="box">
			<view class="">
				<view class="">
					姓名:
				</view>
				<view class="">
					<input maxlength="6" v-model="studentInformation.name" type="text"  />
				</view>
			</view>
			<view class="">
				<view class="">
					年龄:
				</view>
				<view class="">
					<input maxlength="3" type="number" v-model="studentInformation.age"/>
				</view>
			</view>
			<view class="">
				<view class="">
					性别:
				</view>
				<view class="">
					<input maxlength="1" type="text" v-model="studentInformation.sex"  />
				</view>
			</view>
			<view class="">
				<view class="">
					班级:
				</view>
				<view class="">
					<input maxlength="10" type="text" v-model="studentInformation.classNo" />
				</view>
			</view>
			<view class="">
				<view class="">
					籍贯:
				</view>
				<view class="">
					<input maxlength="10" type="text" v-model="studentInformation.ji"  />
				</view>
			</view>
		</view>
		<view class="model_button">
			<button type="primary" @click="send">{{title}}</button>
			<button type="default" @click="yin">取消x</button>
		</view>
		
	</view>
</template>

<script>
	export default {
		props:["title","studentInformation"],
		data() {
			return {
					modelShow:false
			}
		},
		methods: {
			yin(){
				console.log(this.studentInformation)
				this.modelShow = false
			},
			send(){
				
				if(this.title == "修改"){
					let that = this
					uni.request({
						url:"http://localhost:8080/user/setUser/"+this.studentInformation.id+"/"+this.studentInformation.name+"/"+this.studentInformation.age+"/"+this.studentInformation.sex+"/"+this.studentInformation.classNo+"/"+this.studentInformation.ji,
						success(res) {
							if(res.data){
								that.modelShow = false
								 that.$emit("flush1")
								uni.showToast({
								    title: '修改成功',
								    duration: 2000
								});
							}
						}
					})
				}else if(this.title == "增加"){
					let that = this
					console.log(this.studentInformation)
					console.log("--------------")
					uni.request({
						url:"http://localhost:8080/user/addUser/"+this.studentInformation.name+"/"+this.studentInformation.age+"/"+this.studentInformation.sex+"/"+this.studentInformation.classNo+"/"+this.studentInformation.ji,
						success(res) {
							if(res.data){
								that.modelShow = false
								that.$emit("flush1")
								uni.showToast({
								    title: '增加成功',
								    duration: 2000
								});
								
							}
							
						}
					})
				}
			}
		},
		
	}
</script>

<style>
	.model_button{
		display: flex;
		margin-top: 20rpx;
	}
.model{
	width: 100%;
	position: fixed;
	top: 40%;
	left: 50%;
	transform: translate(-50%);
	text-align: center;
	background: #F5F7FA;
}
image{
	max-height: 140rpx;
	width: 80%;
	margin: 0 auto;
}
.title{
	font-size: 50rpx;
	font-weight: bold;
}
.box{
	padding: 0px 20rpx;
	
}
.box>view{
	display: flex;
}
.box>view>view:nth-child(1){
	width: 20%;
	text-align: left;
}
.box>view>view:nth-child(2){
	width: 70%;
	
}
.model input{
	border-bottom: 1px #007AFF solid;
	width: 100%;
}
</style>
